package store.lunangangster.engine.impl.el;

import java.util.HashMap;
import java.util.Map;
import javax.el.ValueExpression;
import javax.el.VariableMapper;

public class DefaultVariableMapper extends VariableMapper {

  protected Map<String, ValueExpression>  valueCache = null;

  @Override
  public ValueExpression resolveVariable(String variable) {
    return valueCache == null ? null : valueCache.get(variable);
  }

  @Override
  public ValueExpression setVariable(String variable, ValueExpression expression) {
    if (valueCache == null) {
      valueCache = new HashMap<>();
    }
    valueCache.put(variable, expression);
    return expression;
  }
}
